const errorType = require("../constans/error-types");

// 检验参数是否为空
const authParams = (ctx, ...params) => {
  params.forEach((it) => {
    if (!it) {
      const error = new Error(errorType.PARAMETER_ERROR);
      throw ctx.app.emit("error", error, ctx);
    }
  });
};

const authParamsBody = (ctx, body) => {
  for (const key in body) {
    if (body[key] === "") {
      const error = new Error(errorType.PARAMETER_ERROR);
      throw ctx.app.emit("error", error, ctx);
    }
  }
};

module.exports = {
  authParams,
  authParamsBody,
};
